function t(t, e, a) {
  return e in t ? Object.defineProperty(t, e, {
    value: a,
    enumerable: !0,
    configurable: !0,
    writable: !0
  }) : t[e] = a, t;
}

var e = getApp();

Page({
  data: {
    titleHeight: 40,
    oldTitleHeight: 40,
    contentHeight: 420,
    oldContentHeight: 420,
    imgList: [],
    addFlag: !1,
    TitleText: "",
    contentText: "",
    state: 0,
    releaseFlag: !0,
    amendImgList: [],
    data_arr: []
  },
  previewImage: function (t) {
    var e = this;
    wx.previewImage({
      current: t.target.dataset.url,
      urls: e.data.imgList
    });
  },
  getTitleText: function (t) {
    this.setData({
      TitleText: t.detail.value
    });
  },
  titleChange: function (t) {
    var e = this,
      a = (e.data.titleHeight, e.data.oldTitleHeight);
    console.log(t), console.log(t.detail.heightRpx), console.log(a), t.detail.heightRpx > a && (2 == t.detail.lineCount ? e.setData({
      titleHeight: 86
    }) : e.setData({
      titleHeight: t.detail.heightRpx
    }));
  },
  getContetnText: function (t) {
    this.setData({
      contentText: t.detail.value
    });
  },
  contentChange: function (t) {
    var e = this,
      a = (e.data.contentHeight, e.data.oldContentHeight);
    t.detail.heightRpx > a ? e.setData({
      contentHeight: t.detail.heightRpx
    }) : e.setData({
      contentHeight: a
    });
    console.log(t)
  },
  chooseImage: function () {
    var t = this,
      e = t.data.imgList;
    wx.chooseImage({
      count: 9,
      sizeType: ["original", "compressed"],
      sourceType: ["album", "camera"],
      success: function (a) {
        if (console.log(a), "chooseImage:ok" == a.errMsg) {
          for (var o = 0; o < a.tempFilePaths.length; o++)
            if (e.push(a.tempFilePaths[o]),
              t.data.amendImgList.push(a.tempFilePaths[o]), e.length >= 9) return void t.setData({
                imgList: e,
                amendImgList: t.data.amendImgList,
                addFlag: !0
              });
          console.log(e), t.setData({
            imgList: e,
            amendImgList: t.data.amendImgList
          }), console.log(t.data.amendImgList);
        }
      },
      fail: function (t) { },
      complete: function (t) { }
    });
  },
  delImage: function (t) {
    console.log(t);
    var a = this,
      o = this.data.imgList,
      n = this.data.amendImgList;
    console.log(n);
    var i = t.currentTarget.dataset.url,
      s = n.indexOf(i);
    console.log(s), -1 != s ? (o.splice(t.currentTarget.dataset.index, 1), n.splice(s, 1),
      o.length < 9 && this.setData({
        addFlag: !1
      }), this.setData({
        imgList: o,
        amendImgList: n
      })) : wx.request({
        url: e.globalData.dic + "doctor/notice/delete/image",
        data: {
          token: a.data.token,
          comMsgInfoId: a.data.msgInfoId,
          imagePath: i
        },
        success: function (e) {
          console.log(e), 200 == e.data.code && (o.splice(t.currentTarget.dataset.index, 1),
            console.log(n), o.length < 9 && a.setData({
              addFlag: !1
            }), a.setData({
              imgList: o
            }));
        }
      });
  },
  switchChange: function (t) {
    console.log(t), t.detail.value ? this.setData({
      state: 1
    }) : this.setData({
      state: 0
    });
  },
  release: function () {
    var t = this,
      a = t.data.imgList
    var teamtext = t.data.contentText
    var title = t.data.TitleText
    if (title == '') {
      wx.showToast({
        title: "请输入标题",
        icon: "none",
        duration: 2e3
      });
    } else if (teamtext == '') {
      wx.showToast({
        title: "请输入内容",
        icon: "none",
        duration: 2e3
      });
    } else {
      //上传图片
      var uniacid = t.data.uniacid
      var data_arr = t.data.data_arr;
      var state = t.data.state
      for (var i = 0; i < a.length; i++) {
        wx.uploadFile({
          url: t.data.url + 'app/index.php?i=' + uniacid + '&c=entry&a=wxapp&do=Upload&m=hyb_yl',
          filePath: a[i],
          name: 'upfile',
          formData: {},
          success: function (res) {
            console.log(res)
            data_arr.push(res.data)
            t.setData({
              data_arr: data_arr
            })
          }
        })
      }
      wx.showToast({
        title: "发布中请稍后......",
        icon: "none",
        duration: 2e3
      });
      setTimeout(function () {
        console.log(data_arr)
        e.util.request({
          'url': 'entry/wxapp/studio.saveteam',
          data: {
            title: title,
            teamtext: teamtext,
            thumbarr: data_arr,
            t_id: t.data.t_id,
            state: state
          },
          success: function (res) {
            console.log(res)
            t.setData({
              url: res.data
            })
          },
        })
        wx.showToast({
          title: "发布成功",
          icon: "success",
          duration: 2e3
        });
      }, 1500)
      setTimeout(() => {
        wx.navigateBack({
          complete: (res) => {},
        })
      }, 500);
      

    }
  },
  onLoad: function (options) {
    var that = this;
    var uniacid = e.siteInfo.uniacid;
    e.util.request({
      'url': 'entry/wxapp/hzbingli.url',
      'cachetime': '0',
      success: function (res) {
        console.log(res)
        that.setData({
          url: res.data
        })
      },
    })
    if (options.bianji) {
      //查询编辑
      e.util.request({
        'url': 'entry/wxapp/studio.addgongg',
        data: {
          g_id: options.g_id,
        },
        success: function (res) {
          console.log(res)
          that.setData({
            releaseFlag: res.data,
            contentText: res.data.teamtext,
            TitleText: res.data.title,
            imgList: res.data.thumbarr,
            state: res.data.menttypes,
          })
        }
      })
    }
    this.setData({
      t_id: options.t_id,
      uniacid: uniacid,
      bianji: options.bianji
    })
  },
  onReady: function () { },
  onShow: function () { },
  onHide: function () { },
  onUnload: function () { },
  onPullDownRefresh: function () { },
  onReachBottom: function () { },
  onShareAppMessage: function () { },
  uploadDIY: function (t, a, o, n) {

  },
  save: function () {
    var t = this,
      a = t.data.amendImgList;
    console.log(a);
    wx.showToast({
      title: "请输入标题",
      icon: "none",
      duration: 2e3
    });
  }
});